﻿using System;
using System.Collections.Generic;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Linq;
using System.Text;

using FRL.DebtChased.Types;

namespace FRL.DebtChased.Repository
{

	/// <summary>
	/// Declaration of Stuffer class
	/// </summary>
	public class Stuffer
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		private Dictionary<string, string> m_primaryMap = new Dictionary<string, string>();
		private Dictionary<string, string> m_targetMap = new Dictionary<string, string>();

		/////////////////////////////////////////////////////////////
		// Constrcution

		public Stuffer( DebtChasedEntities ent, CommTemplate commTemplate, Account account, List<int> InvoiceIds, Definitions.eCommTargetType Target )
		{

			// Build a list of fields
			m_primaryMap.Add(StufferDefinitions.CLIENT_DEARTITLE, "Mr Fred Bloggs");

			// Calculate totals
			List<Money> accountTotalMoney = new List<Money>();
			List<Money> chasingTotalMoney = new List<Money>();
			foreach(AccountInvoice inv in account.AccountInvoices)
			{

				// add to total
				accountTotalMoney.Add(inv.ToMoneyDecimal());

				// If invoice not in query...
				if(inv.IsInQuery)
					chasingTotalMoney.Add(inv.ToMoneyDecimal());

			}
			m_primaryMap.Add(
				StufferDefinitions.ACCOUNT_SUBJECTACCOUNTTOTAL, 
				Money.SuperSmartAddition(accountTotalMoney,false)
			);
			m_primaryMap.Add(
				StufferDefinitions.ACCOUNT_SUBJECTCHASINGTOTAL, 
				Money.SuperSmartAddition(chasingTotalMoney,false)
			);

		}

	}

}


		/*
		public static bool Populate(string strTextIn, Dictionary<string, string> fieldMapA, Dictionary<string, string> fieldMapB, out string strTextOut)
		{

			// Declare a string-builder
			StringBuilder sb = new StringBuilder(strTextIn);

			// Replace fields A
			foreach (var di in fieldMapA)
			{
				string strMarker = string.Format("[%{0}%]", di.Key);
				sb.Replace(strMarker, di.Value);
			}

			// Replace fields B
			foreach (var di in fieldMapB)
			{
				string strMarker = string.Format("[%{0}%]", di.Key);
				sb.Replace(strMarker, di.Value);
			}

			// Update text-out
			strTextOut = sb.ToString();

			// Return true if all markers replaced
			return (!strTextOut.Contains("[%"));

		}
*/